package com.itxx.keyCase.Demo5;

import java.io.*;
import java.net.Socket;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        //1.创建Socket对象

        Socket socket = new Socket("127.0.0.1", 54432);

        //2.通过io流传输数据      创建字节输出流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\develop\\workspace\\Advance_Code\\day15\\src\\com\\itxx\\keyCase\\clientFile\\AAA.jpg"));
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());


        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
            bos.flush();
        }
        socket.shutdownOutput();
        //3.传输完成  服务端会给反应
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println("传输完成后服务器给的反应:" + s);
        }

        //4.释放资源
        bis.close();
        socket.close();

    }
}

